package com.stud.dustteam.dao;

import com.stud.dustteam.model.OrderForSign;
import com.stud.dustteam.util.HibernateUtil;
import org.hibernate.classic.Session;

/**
 * Created with IntelliJ IDEA.
 * User: Shady
 * Date: 13.11.12
 * Time: 16:30
 * To change this template use File | Settings | File Templates.
 */
public class OrderForSignDAO implements DAO <OrderForSign> {

    @Override
    public void create(OrderForSign orderForSign) {
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        session.save(orderForSign);
        session.getTransaction().commit();
    }

    @Override
    public OrderForSign load(Integer id) {
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        OrderForSign orderForSign = (OrderForSign) session.load(OrderForSign.class, id);
        session.getTransaction().commit();
        return orderForSign;
    }

    @Override
    public void delete(Integer id) {
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        OrderForSign orderForSign = (OrderForSign) session.load(OrderForSign.class, id);
        if(null != orderForSign) {
            session.delete(orderForSign);
        }
        session.getTransaction().commit();
    }

    @Override
    public void update(OrderForSign orderForSign) {
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        session.update(orderForSign);
        session.getTransaction().commit();
    }
}
